package com.etc.service.impl.system;


import com.etc.entity.system.SysUser;
import com.etc.repository.system.LoginRepository;
import com.etc.result.CodeMessage;
import com.etc.result.ResultBean;
import com.etc.service.system.ILoginService;
import com.etc.vo.system.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Main 登录业务层
 * @Author zsw
 * @Date 2019/12/1 9:53
 **/

@Service
public class LoginServiceImpl implements ILoginService {

    @Autowired
    private LoginRepository loginRepository;


    @Override
    public ResultBean login(LoginVo loginVo) {
        List<SysUser> byLoginName = loginRepository.findSysUserByLoginName(loginVo.getLoginName());
        if (byLoginName == null || byLoginName.isEmpty()){
            return ResultBean.error(CodeMessage.NULL_LOGIN_NAME.getCode(),CodeMessage.NULL_LOGIN_NAME.getMassage());
        }else {
            SysUser sysUser = byLoginName.get(0);
            if (sysUser.getPassword().equals(loginVo.getPassword())){

                return ResultBean.success();
            }
        }
        return ResultBean.error(CodeMessage.LOGIN_ERROR.getCode(),CodeMessage.LOGIN_ERROR.getMassage());
    }
}
